//
//  ViewController.m
//  UI13-QQ页面
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "MyCell.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,retain)UIScrollView *scrollerView;
@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)UISearchController *searchController;

@end

@implementation ViewController
-(void)dealloc{
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createConfig];
    [self creataView];
}
- (void)createConfig{
    self.scrollerView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 104)];
    self.scrollerView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.scrollerView];
    self.scrollerView.pagingEnabled = YES;
    self.scrollerView.bounces = NO;
    self.scrollerView.scrollEnabled = NO;  //设置scrollerView不可以滑动
    self.scrollerView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 0);
    [_scrollerView release];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
//右面的按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(rightbarbottonAction:)];
//左面的按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 20, 40, 40);
    button.layer.cornerRadius = 20;
    button.layer.masksToBounds = YES;
    button.backgroundColor = [UIColor purpleColor];
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem =leftButton;
//segView
    UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"消息",@"电话"]];
    seg.frame = CGRectMake(0, 20, 120, 40);
    [seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged]; //重点
    [self.navigationItem setTitleView:seg];
    [seg release];
}
- (void)rightbarbottonAction:(UIBarButtonItem *)UIbarbuttonItem{
    
}

- (void)segAction:(UISegmentedControl *)seg{
    switch (seg.selectedSegmentIndex) {
        case 0:
            self.scrollerView.contentOffset = CGPointMake(0, 0);
            break;
        default:
            self.scrollerView.contentOffset = CGPointMake(self.view.frame.size.width, 0);
            break;
    }
}
- (void)creataView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 104) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate =self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 100;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [self.scrollerView addSubview:self.tableView];
    [_tableView release];
    [self.tableView registerClass:[MyCell class] forCellReuseIdentifier:@"cell"];
    _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    _searchController.dimsBackgroundDuringPresentation = NO;
    _searchController.hidesNavigationBarDuringPresentation = NO;
    _searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
    self.tableView.tableHeaderView = self.searchController.searchBar;

}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
//cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    return cell;
}
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewRowAction *deleAction = [UITableViewRowAction rowActionWithStyle:0 title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //数据处理
//        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }];
    UITableViewRowAction *collerAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"收藏" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //数据处理
    }];
    NSArray *array = [NSArray arrayWithObjects:deleAction,collerAction, nil];
    return array;
}

































- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
